package com.ruoyi.quartz.config;


import com.ruoyi.quartz.task.LikeTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

/**
 * @author Bruce
 */
@Configuration
@EnableScheduling
public class QuartzConfig {
    private static final String LIKE_TASK_IDENTITY = "ThumbsQuartz";

    @Bean
    public JobDetail quartzDetail(){
        return JobBuilder.newJob(LikeTask.class).withDescription(LIKE_TASK_IDENTITY).storeDurably().build();
    }


    @Bean
    public Trigger quartzTrigger(){
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
//                .withIntervalInHours(1)
                .withIntervalInSeconds(30)
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(quartzDetail()).withIdentity(LIKE_TASK_IDENTITY)
                .withSchedule(scheduleBuilder).build();
    }
}
